<?php

namespace App\Http\Middleware;

use App\Exceptions\ServiceException;
use App\Http\Constants\CommonExceptionConstants;
use Closure;

class AdminAuth
{


    public function handle($request, Closure $next)
    {
        $user = $request->session()->get('admin_user');
        if ($user) {
            $request->userId = $user['id'];
            view()->share('user', $user);
        } else {
            throw new ServiceException(CommonExceptionConstants::getKey('no_login'));
        }
        return $next($request);
    }

}